#ifndef XMLHANDLE_H
#define XMLHANDLE_H

#include "dataDefination.h"
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QObject>

enum eXmlStatusInfo {
    xmlLoginStatusBase = 0,
    xmlLoginSuccessful,
    xmlLoginFailed,
    xmlRenameSuccessful,
    xmlRenameFailed,
    xmlLogoutSuccessful,
    xmlLogoutFailed,
    xmlLoginStatusEnd,

    xmlNetworkStatusBase = xmlLoginStatusEnd + 1,
    xmlNetworkUnconnected,
    xmlNetworkConnected,
    xmlNetworkError,
    xmlNetworkStatusEnd,

    xmlRecordStatusBase = xmlNetworkStatusEnd + 1,
    xmlRecordReceived,
    xmlRecordError,
    xmlRecordStatusEnd,

    xmlStatusEnd
};

class xmlHandle : public QObject
{
Q_OBJECT

public:
    void userListToXml(QByteArray & data, const QList<userInfo> & list);
    void recordInfoToXml(QByteArray & data, const recordInfo & info);
    void loginToXml(QByteArray & data, const QString & name);
    void logoutToXml(QByteArray & data);
    void pluseToXml(QByteArray & data);
    void statusToXml(QByteArray & data, int code);

    void read(const QString & ip, const QByteArray & data);

private:
    QList<userInfo> xmlToUserList(QXmlStreamReader & xml);
    recordInfo xmlToRecordInfo(QXmlStreamReader & xml);
    QString xmlToLogin(QXmlStreamReader & xml);
    int xmlToStatus(QXmlStreamReader & xml);

signals:
    void sendUserList(QList<userInfo> list);
    void sendPulse(QString ip);
    void sendLogin(QString ip, QString name);
    void sendLogout(QString ip);
    void sendRecordInfo(QString ip, recordInfo info);
    void sendStatus(QString ip, int code);
};

#endif // XMLHANDLE_H
